<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-form ref="form" :model="t_code" :rules="rules" label-width="100px" id="mvcfm">
      <div class="big-title">
        <span class="big-title-left">
          <h1>产品出库</h1>
        </span>
      </div>
      <div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="出库单号" prop="stock_num">
              {{t_code.bar}}
            </el-form-item>
          </el-col>
          <el-col :span="100">
            <span class='required'>*</span> 入库日期
          </el-col>
          <el-col :span="8">
            {{getDateTimeString(t_code,'gettime')}}
          </el-col>
          <el-col :span="8"> 操作人 </el-col>
          <el-col :span="8">
            {{t_code.contact_name}}
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="出库类型" prop="stock_type">
              <el-select style='width:100%' v-model="t_code.stock_type">
                <el-option label="－－无－－" value='' />
                <el-option v-for="dict in s_inout" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-table :data="s_top">
        <el-table-column label="操作" prop="" width="60">
          <template slot-scope="scope">
            <el-link @click="appendRow(s_top,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
            <el-link @click="delRow(s_top,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
          </template>
        </el-table-column>
        <el-table-column label="产品选择" prop="phone_area" width="180">
          <template slot-scope="scope">
            {{scope.row.phone_area}}
            <el-button @click="popDeliveryProChoice('phone_area','product_id')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
          </template>
        </el-table-column>
        <el-table-column label="出库价格" prop="">
          <template slot-scope="scope">
            <el-input v-model="scope.row.product_price" /> 元：
          </template>
        </el-table-column>
        <el-table-column label="数量" prop="">
          <template slot-scope="scope">
            <el-input v-model="scope.row.product_num" />
          </template>
        </el-table-column>
        <el-table-column label="单位" prop="">
          <template slot-scope="scope">
            <el-input v-model="empty" />
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="">
          <template slot-scope="scope">
            <el-input v-model="scope.row.remark" />
          </template>
        </el-table-column>
      </el-table>
      <div>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" v-model="store_stock.remark" ttparea=350></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-button @click="deliveryListSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>出库</el-button>
    </el-form>
    <el-dialog :visible.sync="DeliveryProChoiceVisible" append-to-body>
      <DeliveryProChoice v-if="DeliveryProChoiceVisible" ref="DeliveryProChoice" :popparams="popparams"> </DeliveryProChoice>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import DeliveryProChoice from "@/views/psi/supplychainmana/DeliveryProChoice";
  export default {
    name: 'DeliveryList',
    components: {
      DeliveryProChoice,
    },
    props: ['popparams'],
    data() {
      return {
        DeliveryProChoiceVisible: false,
        DeliveryProChoiceValue: null,
        DeliveryProChoiceDesc: null,
        vueparams: this.getVUEParams(""),
        t_code: {
          bar: null,
          gettime: null,
          contact_name: null,
          stock_type: null,
        },
        s_top: [],
        store_stock: {
          remark: null,
        },
        s_inout: [],
        loading: false,
        rules: {
          stock_num: [{
            required: true,
            message: "出库单号不能为空",
            trigger: 'blur',
          }],
          store_intime: [{
            required: true,
            message: "入库日期不能为空",
            trigger: 'blur',
          }],
        }
      }
    },
    created() {
      this.getData();
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/psi/supplychainmana/DeliveryAction/deliveryList?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      deliveryListSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/psi/supplychainmana/DeliveryAction/deliveryListSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/psi/supplychainmana/DeliveryDetil/deliveryDetil?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      popDeliveryProChoice(desc, value) {
        this.DeliveryProChoiceVisible = true;
        this.DeliveryProChoiceDesc = desc;
        this.DeliveryProChoiceValue = value;
      },
      closeDeliveryProChoice(value, desc) {
        this.DeliveryProChoiceVisible = false;
        this.$set(this.s_top, this.DeliveryProChoiceDesc, desc);
        this.$set(this.s_top, this.DeliveryProChoiceValue, value);
      },
    },
  }
</script>
